﻿using System;
using System.Collections.Generic;
using System.Text;
using ITAP.ShprossesBuilder.Modelling;
using ITAP.ShprossesBuilder.Modelling.Components;
using System.Drawing;
using ITAP.Core.Modelling;

namespace ITAP.ShprossesBuilder.Calculations.CoordinateTransformations
{
    public class GlobalToSelectedCellCoordinateTransformer : ICoordinateTransformer
    {
        private bool enabled = false;

        public bool Enabled
        {
            get { return enabled; }
            set { enabled = value; }
        }
        #region ICoordinateTransformer Members

        public ModelPoint TransformTo(ModelContainer container, ModelPoint point)
        {
            if(container.ActiveCell == null || !enabled)
                return (ModelPoint)point.Clone();

            RectangleF rect = container.ActiveCell.BoundingBox;
            ModelPoint result = new ModelPoint(point.X - rect.X, point.Y - rect.Y);
            return result;
        }

        public ModelPoint TransformFrom(ModelContainer container, ModelPoint point)
        {
            if (container.ActiveCell == null || !enabled)
                return (ModelPoint)point.Clone();

            RectangleF rect = container.ActiveCell.BoundingBox;
            ModelPoint result = new ModelPoint(point.X + rect.X, point.Y + rect.Y);
            return result;            
        }

        #endregion
    }
}
